/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package productions;

import exceptions.ParserException;
import lexico.ErrorTable;
import lexico.SymbolTable;
import lexico.TokenClass;

/**
 *
 * @author Marcone
 */
public class ExprAndProduction extends AbstractProductionRule {

    private static ExprAndProduction instance = new ExprAndProduction();

    public static ExprAndProduction getInstance() {
        return instance;
    }


    /**
     * Regra: expr_and : expr_rel ('&&' expr_rel)*;
     * @return
     * @throws ParserException
     */
    @Override
    public boolean analyze(SymbolTable st, ErrorTable et) throws ParserException {
        if (!ExprRelProduction.getInstance().analyze(st, et)) {
            return false;
        }

        while (basicParse(st, TokenClass.OPERATOR_AND)) {
            if (!ExprRelProduction.getInstance().analyze(st, et)) {
                return skipUntilSynchronize(st, et, "Era esperado uma Expressão.");
            }
        }

        return true;
    }

    @Override
    protected void populateFirst() {
        //from exprrel first
        first.add(TokenClass.OPERATOR_NOT);
        first.add(TokenClass.DELIMITER_OPENING_PARENTHESIS);
        first.add(TokenClass.NUMERIC);
        first.add(TokenClass.NUMERIC_REAL);
        first.add(TokenClass.KEYWORD_VERDADEIRO);
        first.add(TokenClass.KEYWORD_FALSO);
        first.add(TokenClass.IDENTIFIER);
        this.first.add(TokenClass.OPERATOR_PLUS);
        this.first.add(TokenClass.OPERATOR_MINUS);
        first.add(TokenClass.OPERATOR_INCREMENT);
        first.add(TokenClass.OPERATOR_DECREMENT);
        this.first.add(TokenClass.KEYWORD_CAST);
    }

    @Override
    protected void populateFollow() {
        //from expr follow
        follow.add(TokenClass.DELIMITER_COMMA);
        follow.add(TokenClass.DELIMITER_CLOSING_PARENTHESIS);
        follow.add(TokenClass.DELIMITER_SEMICOLON);
        follow.add(TokenClass.DELIMITER_CLOSING_CURLY_BRACKET);
        follow.add(TokenClass.DELIMITER_CLOSING_PARENTHESIS);
        follow.add(TokenClass.DELIMITER_SEMICOLON);
        
        follow.add(TokenClass.OPERATOR_OR);
    }

}
